#ifndef COMMON_H
#define COMMON_H

#include "stdtypes.h"
#include "XString.h"

enum PathType
{
	EPATH_DOC,
	EPATH_APP,
	EPATH_TMP
};

struct ResFile
{
	uint8 *data;
	int    size;
};

class CWebView
{
public:
	CWebView(){m_WebView = NULL;}
	~CWebView(){Hide();}
	void Show(int16 posX,int16 posY,int16 width,int16 height);
	void Hide();
	void SetUrl(CXString url);
	void SetPos(int16 centerX,int16 centerY);
    bool GoBack();
	bool isShowing(){return m_WebView;}
private:
	void * m_WebView;
};

class CWait
{
public:
	CWait(){m_WaitControl = NULL;}
	~CWait(){Hide();}
	void Show(int16 centerX,int16 centerY,int16 width = 20,int16 height = 20);
	void Hide();
	void SetPos(int16 centerX,int16 centerY);
	bool isWaiting(){return m_WaitControl;}
private:
	void * m_WaitControl;
};

enum {DTYPE_DNAME,DTYPE_IMEI,DTYPE_SYSVER,DTYPE_LANGUAGE,DTYPE_APPVER,DTYPE_CARRIER,DTYPE_NETTYPE};
class Common 
{
public:
	static CXString GetDeviceMsg( int16 type );
	static void LaunchURL( const char * pName );
	static boolean ReadFile(CXString filename,ResFile& resfile,PathType type=EPATH_APP);
	static boolean WriteFile(CXString filename,ResFile& resfile,PathType type=EPATH_APP);
	static void ShowMsg(CXString title,CXString msg);
	static CXString GetSysPath(PathType type=EPATH_APP);
	static CXString GetFileName(CXString fullpath);
	static boolean IsFileExist(CXString fullpath);
	static boolean PredicateCheck(CXString spcode,CXString checkTxt);
	static CXString TimeNow(CXString format = "yyyyMMddHHmmss");
	static CXString MD5(CXString str);
	static void SendEmail(CXString address,CXString title,CXString body,bool isHtml = false);
	static void SavedPhotosAlbum(CXString picpath);
};

class DataStream
{
public:
	DataStream();
	~DataStream();
	
	void SetStream(int8 * buffer,bool isJavaData);

	void writeByte(int8 data);
	void writeShort(int16 data);
	void writeInt(int32 data);

	int8  readByte();
	int16 readShort();
	int32 readInt();

	void writeUTF(CXString& data);
	void readUTF(CXString& data);

	void  SetOffSet(int32 offset);
	int32 GetOffSet();
private:
	int8  *m_pData;
	int32  m_iOffset;
	bool   m_bIsJavaData;
};

#endif